using System;

namespace DotConferenceSql
{
    /// <summary>
    /// The generic INNER JOIN clause element
    /// </summary>
    public class InnerJoinQueryElement : QueryElementBase
    {
        private string m_foreignTable = String.Empty;
        /// <summary>
        /// Gets or sets the foreign table.
        /// </summary>
        /// <value>The foreign table.</value>
        public string ForeignTable
        {
            get
            {
                return m_foreignTable;
            }
            set
            {
                m_foreignTable = value;
            }
        }

        private string m_condition;
        /// <summary>
        /// Gets or sets the condition.
        /// </summary>
        /// <value>The condition.</value>
        public string Condition
        {
            get
            {
                return m_condition;
            }
            set
            {
                m_condition = value;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="InnerJoinQueryElement"/> class.
        /// </summary>
        public InnerJoinQueryElement()
            : base()
        {
            Type = QueryElementType.InnerJoinClause;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="InnerJoinQueryElement"/> class.
        /// </summary>
        /// <param name="foreignTable">The foreign table.</param>
        /// <param name="condition">The condition.</param>
        public InnerJoinQueryElement(string foreignTable, string condition)
            : base()
        {
            Type = QueryElementType.InnerJoinClause;
            ForeignTable = foreignTable;
            Condition = condition;
        }

        /// <summary>
        /// Generate the part of the query for this element.
        /// </summary>
        /// <returns>generated SQL fragment</returns>
        public override string BuildTextQuery()
        {
            return String.Format(" INNER JOIN {0} ON {1}", ForeignTable, Condition);
        }
    }
}